<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="python,">





  <link rel="alternate" href="/atom.xml" title="Mr.赵" type="application/atom+xml">






<meta name="keywords" content="python">
<meta property="og:type" content="article">
<meta property="og:title" content="Python集训笔记">
<meta property="og:url" content="https://GodPang.github.io/2018/09/20/Python集训笔记/index.html">
<meta property="og:site_name" content="Mr.赵">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/006doHETly1fwq24e52h3j31hc0u0ag7.jpg">
<meta property="og:updated_time" content="2018-10-30T02:49:37.108Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Python集训笔记">
<meta name="twitter:image" content="http://ww1.sinaimg.cn/large/006doHETly1fwq24e52h3j31hc0u0ag7.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://GodPang.github.io/2018/09/20/Python集训笔记/">





  <title>Python集训笔记 | Mr.赵</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
    
    <a href="https://GodPang.github.io" class="github-corner" aria-label="View source on Github"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Mr.赵</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-首页">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-关于">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-标签">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-类别">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            类别
          </a>
        </li>
      
        
        <li class="menu-item menu-item-归档">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://GodPang.github.io/2018/09/20/Python集训笔记/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="GodPang">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/touxiang.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Mr.赵">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Python集训笔记</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-09-20T23:11:06+08:00">
                2018-09-20
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="/categories/python学习/" itemprop="url" rel="index">
                    <span itemprop="name">python学习</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/09/20/Python集训笔记/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2018/09/20/Python集训笔记/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-eye"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <html><head><meta name="generator" content="Hexo 3.9.0"></head><body><p><img src="http://ww1.sinaimg.cn/large/006doHETly1fwq24e52h3j31hc0u0ag7.jpg" alt=""></p>
<a id="more"></a>
<h1 id="Python"><a href="#Python" class="headerlink" title="Python"></a>Python</h1><h2 id="内置对象"><a href="#内置对象" class="headerlink" title="内置对象"></a>内置对象</h2><table>
<thead>
<tr>
<th>对象类型</th>
<th>例子</th>
</tr>
</thead>
<tbody><tr>
<td>数字</td>
<td>12，1.2,1+2j</td>
</tr>
<tr>
<td>字符串</td>
<td>‘afds’，”fdsaf’dsf”</td>
</tr>
<tr>
<td>列表</td>
<td>[5,3,2,1],[1,[2,’three’],4]</td>
</tr>
<tr>
<td>字典</td>
<td>{‘food’:’spam’,’taste’:’yum’}</td>
</tr>
<tr>
<td>元组</td>
<td>(1,’spam’,4,’U’)</td>
</tr>
<tr>
<td>集·合</td>
<td>set(‘abc’),{‘a’,’b’,’c’}</td>
</tr>
<tr>
<td>布尔型</td>
<td>True，False</td>
</tr>
<tr>
<td>None</td>
<td>None</td>
</tr>
<tr>
<td>##  空值None</td>
<td></td>
</tr>
</tbody></table>
<blockquote>
<ol>
<li>用来语法占位</li>
<li>变量解除锁定</li>
</ol>
</blockquote>
<h2 id="表达式"><a href="#表达式" class="headerlink" title="表达式"></a>表达式</h2><p>1+2*3</p>
<h2 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h2><table>
<thead>
<tr>
<th>运算符</th>
<th>释义</th>
</tr>
</thead>
<tbody><tr>
<td>+</td>
<td>加法</td>
</tr>
<tr>
<td>-</td>
<td>减法</td>
</tr>
<tr>
<td>*</td>
<td>乘法</td>
</tr>
<tr>
<td>/</td>
<td>除法</td>
</tr>
<tr>
<td>//</td>
<td>整除、地板除</td>
</tr>
<tr>
<td>%</td>
<td>取余</td>
</tr>
<tr>
<td>**</td>
<td>幂运算</td>
</tr>
<tr>
<td>is/is not</td>
<td>判定是否为同一对象</td>
</tr>
<tr>
<td>复合运算符</td>
<td>进行复合合运算</td>
</tr>
<tr>
<td>比较运算符</td>
<td>>、<、==、!=< td="">
</、==、!=<></td></tr>
<tr>
<td></td>
<td>(不可以使用<>或><)< td="">
</)<></td></tr>
<tr>
<td>遵守数学运算优先级。</td>
<td></td>
</tr>
</tbody></table>
<hr>
<hr>
<hr>
<center>START</center>

<hr>
<hr>
<hr>
<h2 id="基本输出函数"><a href="#基本输出函数" class="headerlink" title="基本输出函数"></a>基本输出函数</h2><p>格式：<br>    <b>print(‘哈罗世界！’)</b></p>
<p>事例：</p>
<ul>
<li>print(1+2*3)</li>
<li>print(‘asfas”)</li>
<li>print(1+2,3+4,100)</li>
<li>a=10  print(a)</li>
</ul>
<h2 id="变量"><a href="#变量" class="headerlink" title="变量"></a>变量</h2><p>定义：</p>
<blockquote>
<p>   关联一个对象的标识符（符号）。</p>
</blockquote>
<p>作用：</p>
<blockquote>
<p>   用来绑定一个数据对象，以便以后重复使用。</p>
</blockquote>
<p>命名方法：</p>
<blockquote>
<ol>
<li>必须为字母或下划线开头，可由字母、下划线、数字组成</li>
<li>不能使用python关键字（保留字）</li>
<li>区分大小写</li>
</ol>
</blockquote>
<h2 id="赋值语句-statement"><a href="#赋值语句-statement" class="headerlink" title="赋值语句    statement"></a>赋值语句    statement</h2><p>符号：  =</p>
<p>语法：</p>
<blockquote>
<ul>
<li>变量名 = 表达式</li>
<li>变量名1 = 变量名2 = 表达式</li>
<li>变量名1,变量名2,…… = 序列</li>
</ul>
</blockquote>
<p>作用：</p>
<blockquote>
<p>  用于将一个变量绑定在一个对象上</p>
</blockquote>
<p>说明：</p>
<blockquote>
<ol>
<li>当变量不存在时，创建该变量，并绑定此变量</li>
<li>当变量存在时，改变此变量的绑定关系</li>
<li>一个变量只能绑定一个对象</li>
<li>两个变量可以同时绑定同一个对象</li>
<li>等号可以理解为：赋值、引用、指针</li>
</ol>
</blockquote>
<p>示例：</p>
<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">import math</span><br><span class="line">r=3</span><br><span class="line">print('C=',2*r*math.pi)</span><br><span class="line">print('S=',r**2*math.pi)</span><br></pre></td></tr></tbody></table></figure>

<p>交换变量：</p>
<blockquote>
<p>a,b = b,a</p>
</blockquote>
<hr>
<h2 id="函数"><a href="#函数" class="headerlink" title="函数"></a>函数</h2><p>id(x)</p>
<blockquote>
<p>返回一个对象在内存中的地址</p>
</blockquote>
<p>del 变量名</p>
<blockquote>
<p>删除变量同时解除与对象的关联关系</p>
</blockquote>
<p>自动化内存管理和引用计数：</p>
<blockquote>
<p>每个对象都会记录有几个变量引用自身，当引用的数量为零的时候，此对象将被销毁</p>
</blockquote>
<p>complex(a,b)</p>
<blockquote>
<p>(a+bj）</p>
</blockquote>
<p>bool(x)</p>
<blockquote>
<p>x=0或x空时，返回False，其他情况返回True</p>
</blockquote>
<p>int(x) float(x)……</p>
<blockquote>
<p>转换变量类型</p>
</blockquote>
<p>abs(x)</p>
<blockquote>
<p>取绝对值</p>
</blockquote>
<p>round(数值[,精确值])</p>
<blockquote>
<p>四舍五入，保留位数</p>
</blockquote>
<p>help()</p>
<blockquote>
<p>查看函数帮助</p>
</blockquote>
<h2 id="语句-statements"><a href="#语句-statements" class="headerlink" title="语句 statements"></a>语句 statements</h2><ul>
<li>a = 10</li>
<li>del a</li>
<li>print(100)<blockquote>
<p>语句时python执行的最小单位，语句可以独立执行</p>
</blockquote>
</li>
</ul>
<p>说明：</p>
<blockquote>
<p>多条语句写在一行内需要用分号分开<br>通常一条语句写作一行内</p>
</blockquote>
<p>折行符 \</p>
<blockquote>
<p>折行符是告诉解释执行器，下一行的语句也是此语句的内容</p>
</blockquote>
<p>隐式换行：</p>
<blockquote>
<p>所有的括号里内容换行时，解释执行器会自动去下一行找到对应的括号，<br>直到找到为止，称作隐式换行</p>
</blockquote>
<h2 id="基本输入输出函数："><a href="#基本输入输出函数：" class="headerlink" title="基本输入输出函数："></a>基本输入输出函数：</h2><p>输入函数：input</p>
<p>作用：</p>
<blockquote>
<p>从标准输入设备上读取一个字符串</p>
<p>a = int(input())</p>
<p> (注：末尾换行符会被删除)</p>
</blockquote>
<p>格式：</p>
<blockquote>
<p>input（’提示字符串’）</p>
<p>注：返回一个字符串，提示字符串可以为空z<br>输出函数 print()</p>
</blockquote>
<p>作用：</p>
<blockquote>
<p>将一系列的值以字符的形式输出到标准设备上，默认为终端</p>
</blockquote>
<p>格式：</p>
<blockquote>
<p>print(value, … ,sep=’ ’,end=’\n’)</p>
</blockquote>
<p>关键字参数说明：</p>
<blockquote>
<p>sep:两个值之间的分隔符，默认为一个空格’ ‘</p>
<p>end:输出完毕后在流末尾自动追加一个字符串，默认为换行符’\n’</p>
</blockquote>
<h2 id="if-语句"><a href="#if-语句" class="headerlink" title="if 语句"></a>if 语句</h2><p>作用：</p>
<blockquote>
<p>让程序根据条件选择性的执行某条语句或某些语句</p>
</blockquote>
<p>语法：</p>
<pre><code>
If 真值表达式1：
    语句块1…
elif 真值表达式2：
    语句块2…
    …
else:
    语句块n…
</code></pre>
<p>说明：</p>
<blockquote>
<ol>
<li>真值判断会自上而下进行，如果有一条为true则执行其中的语句块，<br>然后结束if语句的执行，如果所有真值表达式都为False，则执行else子句里的语句</li>
<li>elif子句可以有0个，1个或多个</li>
<li>else子句可以有0个，或1个</li>
</ol>
</blockquote>
<h1 id="DAY2"><a href="#DAY2" class="headerlink" title="DAY2"></a>DAY2</h1><h2 id="if语句的嵌套"><a href="#if语句的嵌套" class="headerlink" title="if语句的嵌套"></a>if语句的嵌套</h2><blockquote>
<p>if语句本身是由多条子句组成的一条复合语句</p>
<p>if语句可以作为语句嵌套到另一个语句的内部</p>
</blockquote>
<p>练习：写一个程序，输入一个数，用if语句计算并打印这个数的绝对值</p>
<p>注：不能用abs语句</p>
<pre><code>
A = int(input('请输入一个数'))
if A < 0:
    print(-A)
else:
    print(A)
</code></pre>
<hr>
<pre><code>
A = int(input('请输入一个数'))
if A < 0:
    A = -A
print(A)
</code></pre>

<h2 id="条件表达式"><a href="#条件表达式" class="headerlink" title="条件表达式"></a>条件表达式</h2><p>语法：</p>
<blockquote>
<p>表达式1   if真值表达式   else   表达式2</p>
</blockquote>
<p>作用：</p>
<blockquote>
<p>如果真值表达式的布尔值为True时，则执行表达式1，并返回结果对象的引用，否者表达式2，并返回对象引用。</p>
</blockquote>
<p>例子：</p>
<p>商场促销，满100减20</p>
<pre><code>
money = int(input('请输入商品金额：'))
pay = money - 20 if money >= 100 else money
print('您需要支付：',pay,'元')
</code></pre>

<p>练习：输入一个数，用条件表达式计算并打印这个数的绝对值。</p>
<pre><code>
n = int(input('请输入一个数：'))
print(n if n > 0 else - n)
</code></pre>

<h2 id="pass语句"><a href="#pass语句" class="headerlink" title="pass语句"></a>pass语句</h2><p>作用：通常用来填充语法空白</p>
<ul>
<li>def fun（）：</li>
<li>pass</li>
<li>fun ()</li>
</ul>
<p>布尔运算：</p>
<blockquote>
<p>运算符： not and or</p>
</blockquote>
<p>布尔非操作 not</p>
<p>not x</p>
<blockquote>
<p>作用：对X进行布尔非取值，如bool(x)为True则返回False，否则返回True</p>
</blockquote>
<p>布尔操作and</p>
<p>x and y</p>
<table>
<thead>
<tr>
<th align="center">表达式</th>
<th align="center">结果</th>
</tr>
</thead>
<tbody><tr>
<td align="center">True and True</td>
<td align="center"># True</td>
</tr>
<tr>
<td align="center">True and False</td>
<td align="center"># False</td>
</tr>
<tr>
<td align="center">False and False</td>
<td align="center"># False</td>
</tr>
<tr>
<td align="center">False and False</td>
<td align="center"># False</td>
</tr>
</tbody></table>
<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">if  1<= x="" <="12:" #if="" 1<="x" and=""><br><span class="line">	print("合法月份")</span><br></=></span></pre></td></tr></tbody></table></figure>

<p>布尔或运算 or</p>
<p>x or y # 等同于 x if bool(x)==True  else y</p>
<p>思考： S = input(‘请输入学生的成绩：’) or ‘0’</p>
<blockquote>
<ul>
<li>bool(‘’)</li>
<li>bool([])</li>
</ul>
</blockquote>
<h2 id="正负号运算符"><a href="#正负号运算符" class="headerlink" title="正负号运算符"></a>正负号运算符</h2><p>正负号运算符式一元运算符（只有一个元素参与）</p>
<blockquote>
<ul>
<li>a = 5</li>
<li>b = -a</li>
<li>d = (2 - 3j)</li>
<li>e = -d #(-2+3j)</li>
</ul>
</blockquote>
<hr>
<p>调用库</p>
<blockquote>
<ul>
<li>import math</li>
<li>math.pi</li>
<li>math.sqrt(81)</li>
</ul>
</blockquote>
<p>随机整数</p>
<blockquote>
<ul>
<li>import random</li>
<li>random.randint(0,100)</li>
<li>random,choice([1,2,3,9]) #从固定数组中抽取</li>
</ul>
</blockquote>
<pre><code>
S = 'Spam'
len(s)
S[0]
S[1]
S[4]
切片：
S[1:3]
S + 'xyz'
=>Spamxyz
</code></pre>

<p>L[ : : -1]</p>
<blockquote>
<p>#[起始：终止：步长]</p>
</blockquote>
<p>L.append(‘OK’)</p>
<blockquote>
<p>将ok添加到L表中</p>
</blockquote>
<p>L.pop(2)</p>
<blockquote>
<p>弹出表中相应位置元素 （）为空弹出最后一个</p>
</blockquote>
<p>M.sort</p>
<blockquote>
<p>对M表格排正序</p>
</blockquote>
<p>M.reverse（）</p>
<blockquote>
<p>对表格排倒序</p>
</blockquote>
<p>L[1] = L [:]</p>
<blockquote>
<p>L[:]是L的拷贝</p>
</blockquote>
<hr>
<h1 id="循环语句"><a href="#循环语句" class="headerlink" title="循环语句"></a>循环语句</h1><h2 id="for循环"><a href="#for循环" class="headerlink" title="for循环:"></a>for循环:</h2><figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">for .... in .....:</span><br><span class="line">	语句块</span><br><span class="line">`</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">names = [<span class="string">'zhang'</span>,<span class="string">'wang'</span>,<span class="string">'li'</span>]</span><br><span class="line"><span class="keyword">for</span> name <span class="keyword">in</span> names:</span><br><span class="line">	print(name)</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">sum = <span class="number">0</span></span><br><span class="line"><span class="keyword">for</span> x <span class="keyword">in</span> [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>]:</span><br><span class="line">	sum += x</span><br><span class="line">print(sum)</span><br></pre></td></tr></tbody></table></figure>

<h2 id="range-函数"><a href="#range-函数" class="headerlink" title="range()函数"></a>range()函数</h2><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">range(<span class="number">10</span>)</span><br><span class="line">=>range(0,10)</span><br><span class="line">list(range(<span class="number">10</span>))</span><br><span class="line">从零到九</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> x <span class="keyword">in</span> range(<span class="number">10</span>,<span class="number">20</span>,<span class="number">2</span>):    <span class="comment">#起始，终止，步长</span></span><br><span class="line">	<span class="keyword">print</span>（x）</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">d = {<span class="string">'a'</span>:<span class="number">3</span>,<span class="string">'b'</span>:<span class="number">4</span>,<span class="string">'c'</span>:<span class="number">5</span>}  <span class="comment">#字典</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> d:</span><br><span class="line">	print(i)</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> d.keys():     <span class="comment">#键</span></span><br><span class="line">	print(i)</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> d.valuse():  <span class="comment">#值</span></span><br><span class="line">	<span class="keyword">print</span>（i）</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> k,v <span class="keyword">in</span> d.items():    <span class="comment">#同时迭代key和valuse</span></span><br><span class="line">	print(k,v)</span><br></pre></td></tr></tbody></table></figure>

<h2 id="循环嵌套"><a href="#循环嵌套" class="headerlink" title="循环嵌套"></a>循环嵌套</h2><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">10</span>,<span class="number">31</span>,<span class="number">10</span>):</span><br><span class="line">	print(i)</span><br><span class="line">	<span class="keyword">for</span> j <span class="keyword">in</span> range(<span class="number">3</span>):</span><br><span class="line">		print(j)</span><br></pre></td></tr></tbody></table></figure>

<h2 id="while循环："><a href="#while循环：" class="headerlink" title="while循环："></a>while循环：</h2><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">sum = <span class="number">0</span></span><br><span class="line">n = <span class="number">99</span> </span><br><span class="line"><span class="keyword">while</span> n > <span class="number">0</span>:</span><br><span class="line">	sum = sum - n</span><br><span class="line">	n = n - <span class="number">2</span></span><br><span class="line">print(sum)</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">n = <span class="number">1</span></span><br><span class="line"><span class="keyword">while</span> n < = <span class="number">100</span>:</span><br><span class="line">	<span class="keyword">if</span> n > <span class="number">10</span>:</span><br><span class="line">		<span class="keyword">break</span>   <span class="comment"># break语句会终止循环</span></span><br><span class="line">	print(n)</span><br><span class="line">	n = n + <span class="number">1</span></span><br><span class="line">print(<span class="string">'end'</span>)</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">n = <span class="number">0</span></span><br><span class="line"><span class="keyword">while</span> n < <span class="number">10</span> :</span><br><span class="line">	n = n + <span class="number">1</span></span><br><span class="line">	<span class="keyword">if</span> n % <span class="number">2</span> == <span class="number">0</span>:</span><br><span class="line">		<span class="keyword">continue</span>   <span class="comment">#跳过本次循环，继续执行下一次循环</span></span><br><span class="line">	print(n)</span><br></pre></td></tr></tbody></table></figure>

<h2 id="用循环生成列表"><a href="#用循环生成列表" class="headerlink" title="用循环生成列表"></a>用循环生成列表</h2><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">L = []</span><br><span class="line">n = <span class="number">1</span></span><br><span class="line"><span class="keyword">while</span> n <= <span="" class="number">29</=></span>:<br><span class="line">	L.append(n)</span><br><span class="line">	n = n + <span class="number">2</span></span><br><span class="line">print(L)</span><br></pre></td></tr></tbody></table></figure>

<p>列表解析：（列表推导式，列表生成式）</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">J = [x*<span class="number">2</span> <span class="keyword">for</span> x <span class="keyword">in</span> range(<span class="number">1</span>,<span class="number">30</span>,<span class="number">2</span>)]</span><br><span class="line">print(J)</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">N = [[1,2,3],[4,5,6],[7,8,9]]</span><br><span class="line">col2 = [row[1] + 10 for row in N]</span><br><span class="line">print(col2)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">col2 = [row[1] + 10 for row in N if row[1] % 2 == 0]</span><br><span class="line">print(col2)</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">doubles = [c *<span class="number">2</span> <span class="keyword">for</span> c <span class="keyword">in</span> <span class="string">'spam'</span>]</span><br><span class="line">print(doubles)</span><br></pre></td></tr></tbody></table></figure>

<hr>
<blockquote>
<p>案例：</p>
</blockquote>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">y = int(input(<span class="string">'please input a mnumber:'</span>))</span><br><span class="line">x = y // <span class="number">2</span></span><br><span class="line"><span class="keyword">while</span> x > <span class="number">1</span>:</span><br><span class="line">	<span class="keyword">if</span> y % x == <span class="number">0</span>:</span><br><span class="line">	print(y,<span class="string">'has factor'</span>,x)</span><br><span class="line">	<span class="keyword">break</span></span><br><span class="line">x -= <span class="number">1</span></span><br><span class="line"><span class="keyword">else</span>:      <span class="comment">#当循环正常终止时（非break），执行else语句块</span></span><br><span class="line">	print(y,<span class="string">'is prime'</span>)</span><br></pre></td></tr></tbody></table></figure>

<blockquote>
<p>求出100以内所有质数，用for循环来写</p>
</blockquote>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">end = int(input(<span class="string">'输入数:'</span>))</span><br><span class="line">zhishu = []</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> n <span class="keyword">in</span> range(<span class="number">2</span>,end + <span class="number">1</span>):</span><br><span class="line">    <span class="keyword">for</span> m <span class="keyword">in</span> range(<span class="number">2</span> , n):</span><br><span class="line">        <span class="keyword">if</span> n % m == <span class="number">0</span>:</span><br><span class="line">            <span class="keyword">break</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        zhishu.append(n)</span><br><span class="line">print(<span class="string">'计算结果是：'</span>)</span><br><span class="line">print(zhishu)</span><br></pre></td></tr></tbody></table></figure>

<blockquote>
<p>优化</p>
</blockquote>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">end = int(input(<span class="string">'输入数:'</span>))</span><br><span class="line">zhishu = []</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> n <span class="keyword">in</span> range(<span class="number">2</span>,end + <span class="number">1</span>):</span><br><span class="line">    <span class="keyword">for</span> m <span class="keyword">in</span> range(<span class="number">2</span> , n):</span><br><span class="line">        <span class="keyword">if</span> m ** <span class="number">2</span> > n:</span><br><span class="line">            zhishu.append(n)</span><br><span class="line">            <span class="keyword">break</span></span><br><span class="line">        <span class="keyword">if</span> n % m == <span class="number">0</span>:</span><br><span class="line">            <span class="keyword">break</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        zhishu.append(n)</span><br><span class="line">print(<span class="string">'计算结果是：'</span>)</span><br><span class="line">print(zhishu)</span><br></pre></td></tr></tbody></table></figure>

<h1 id="DAY3"><a href="#DAY3" class="headerlink" title="DAY3"></a>DAY3</h1><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">N = [[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>],[<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>],[<span class="number">7</span>,<span class="number">8</span>,<span class="number">9</span>]]</span><br><span class="line">M = [x[y] <span class="keyword">for</span> x <span class="keyword">in</span> N <span class="keyword">for</span> y <span class="keyword">in</span> range(<span class="number">3</span>)]</span><br><span class="line">print(M)</span><br></pre></td></tr></tbody></table></figure>

<p>列表推到式求出100以内质数</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[x <span class="keyword">for</span> x <span class="keyword">in</span> range (<span class="number">2</span>,<span class="number">101</span>) <span class="keyword">if</span> <span class="keyword">True</span>]</span><br><span class="line">[x <span class="keyword">for</span> x <span class="keyword">in</span> range (<span class="number">2</span>,<span class="number">101</span>) <span class="keyword">if</span> [y <span class="keyword">for</span> y <span class="keyword">in</span> range (<span class="number">2</span>,x) <span class="keyword">if</span> x % y != <span class="number">0</span>]]   <span class="comment">#错，不充分</span></span><br><span class="line">[x <span class="keyword">for</span> x <span class="keyword">in</span> range (<span class="number">2</span>,<span class="number">101</span>) <span class="keyword">if</span> <span class="keyword">not</span> Flase]</span><br><span class="line">[x <span class="keyword">for</span> x <span class="keyword">in</span> range (<span class="number">2</span>,<span class="number">101</span>) <span class="keyword">if</span> <span class="keyword">not</span> [y <span class="keyword">for</span> y <span class="keyword">in</span> range (<span class="number">2</span>,x) <span class="keyword">if</span> x % y == <span class="number">0</span>]]</span><br></pre></td></tr></tbody></table></figure>

<p>假如有一个列表中有很多数据，里面有重复的数据，例如：L：[9,8,7,6,5,4,3,2,1….]打印出列表中的数据，要求重复的只打印一次，打印的顺序一列表中第一次出现的循序为准。例如上述打印：[9,8,7,6,5,4….]</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">L = [<span class="number">9</span>,<span class="number">8</span>,<span class="number">6</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">6</span>,<span class="number">0</span>,<span class="number">4</span>,<span class="number">2</span>,<span class="number">4</span>,<span class="number">9</span>]</span><br><span class="line">result = []</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> x <span class="keyword">in</span> L[:]:</span><br><span class="line">	<span class="keyword">if</span> x <span class="keyword">not</span> <span class="keyword">in</span> result:      <span class="comment"># not</span></span><br><span class="line">		resust.append(x)</span><br><span class="line">print(result)</span><br></pre></td></tr></tbody></table></figure>

<h2 id="斐波那契数列："><a href="#斐波那契数列：" class="headerlink" title="斐波那契数列："></a>斐波那契数列：</h2><p>1,1,2,3,5,8,13,21,34,…..<br>求前40个数</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">fibs = [<span class="number">1</span>,<span class="number">1</span>]</span><br><span class="line">a = <span class="number">1</span></span><br><span class="line">b = <span class="number">1</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span> len(fibs) < <span class="number">40</span>:</span><br><span class="line">	f = a + b</span><br><span class="line">	a = b</span><br><span class="line">	b = f</span><br><span class="line">	fibs.appeds(f)</span><br><span class="line">print(fibs)</span><br></pre></td></tr></tbody></table></figure>

<p>法2 ：</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">fibs = [<span class="number">1</span>,<span class="number">1</span>]</span><br><span class="line"><span class="keyword">while</span> len(fibs) < <span class="number">40</span> :</span><br><span class="line">	fibs.append(fibs[<span class="number">-2</span>] + fibs[<span class="number">-1</span>])</span><br><span class="line">print(fibs)</span><br></pre></td></tr></tbody></table></figure>

<blockquote>
<p>练习：编写程序，计算并打印数列前20项之和：<br>2/1,3/2,5/3,8/5,13/8,21/13 …</p>
</blockquote>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">fibs = [<span class="number">1</span>, <span class="number">2</span>]</span><br><span class="line">s = []</span><br><span class="line"><span class="keyword">for</span> x <span class="keyword">in</span> range(<span class="number">20</span>):                     <span class="comment">#range(20) -> range(0,20)</span></span><br><span class="line">	s.append(fibs[<span class="number">-1</span>]/fibs[<span class="number">-2</span>])</span><br><span class="line">	fibs.append(fibs[<span class="number">-2</span>] + fibs[<span class="number">-1</span>])</span><br><span class="line">print(sum(s))</span><br></pre></td></tr></tbody></table></figure>

<h2 id="函数-1"><a href="#函数-1" class="headerlink" title="函数"></a>函数</h2><h3 id="函数的语法："><a href="#函数的语法：" class="headerlink" title="函数的语法："></a>函数的语法：</h3><figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">def 函数名(参数列表)：</span><br><span class="line">	“函数文档字符串”</span><br><span class="line">	函数语句块</span><br></pre></td></tr></tbody></table></figure>

<h3 id="函数的作用："><a href="#函数的作用：" class="headerlink" title="函数的作用："></a>函数的作用：</h3><ul>
<li>定义用户的函数</li>
<li>函数是可以重复执行的代码块，可以重复使用</li>
<li>函数的名字就是代码块的名字</li>
<li>函数的名字是一个变量(不要轻易对其赋值)</li>
<li>函数有自己的命名空间，不要让函数处理的外部的数据需要使用参数传入</li>
</ul>
<h3 id="函数的调用"><a href="#函数的调用" class="headerlink" title="函数的调用"></a>函数的调用</h3><pre><code>函数名(实际参数)</code></pre><h4 id="return-语句"><a href="#return-语句" class="headerlink" title="return 语句"></a>return 语句</h4><p>语法：</p>
<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">return 表达</span><br><span class="line">或</span><br><span class="line">return             #默认 return None</span><br></pre></td></tr></tbody></table></figure>

<p>作用：</p>
<blockquote>
<p>结束当前函数的执行，返回到调用函数的地方，同时返回一个值对象的引用</p>
</blockquote>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">mymax</span><span class="params">(a1, a2)</span>:</span></span><br><span class="line">	m = a1</span><br><span class="line">	<span class="keyword">if</span> a2 > m:</span><br><span class="line">		m = a2</span><br><span class="line">	<span class="keyword">return</span> m</span><br><span class="line"></span><br><span class="line">x = <span class="number">100</span></span><br><span class="line">y = <span class="number">200</span></span><br><span class="line">print(mymax(x,y))</span><br></pre></td></tr></tbody></table></figure>

<h4 id="位置参数"><a href="#位置参数" class="headerlink" title="位置参数"></a>位置参数</h4><blockquote>
<p>实际参数的对应关系与形式参数的对应关系是以位置来一次对应的</p>
</blockquote>
<p>说明：位置参数，形式参数的个数必须与实际参数的个数相同</p>
<p>练习：写出一个求最小值的函数，包含三个参数，返回最小值</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">mymin</span> <span class="params">(x,y,z)</span>:</span></span><br><span class="line">	<span class="keyword">if</span> x < y:</span><br><span class="line">		min = x</span><br><span class="line">	<span class="keyword">if</span> min > z:</span><br><span class="line">		min = z</span><br><span class="line">	<span class="keyword">return</span> min</span><br><span class="line">x = int(input(<span class="string">'please input x:'</span>))</span><br><span class="line">y = int(input(<span class="string">'please input y:'</span>))</span><br><span class="line">z = int(input(<span class="string">'please input z:'</span>))</span><br><span class="line">print(mymin(x,y,z))</span><br></pre></td></tr></tbody></table></figure>

<p>写一个函数isprime(x)判断x是否为质数，如果为质数，返回True，否者返回Flase</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">isprime</span><span class="params">(x)</span>:</span></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">2</span>,x + <span class="number">1</span>)</span><br><span class="line">		<span class="keyword">if</span> i ** <span class="number">2</span> > x:</span><br><span class="line">			<span class="keyword">return</span> Ture</span><br><span class="line">			<span class="keyword">break</span></span><br><span class="line">		<span class="keyword">if</span> n % i == <span class="number">0</span>:</span><br><span class="line">			<span class="keyword">return</span> <span class="keyword">False</span></span><br><span class="line">	<span class="keyword">return</span> <span class="keyword">False</span>             <span class="comment">#防止负数</span></span><br><span class="line">x = int(input(<span class="string">'please input x:'</span>))</span><br><span class="line">print(isprime(x))</span><br></pre></td></tr></tbody></table></figure>

<p>写一个函数prime_m2n(m,n)，返回从m开始，到n结束范围内的质数，并返回这些质数列表，并打印：</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">prime_m2n</span><span class="params">(m,n)</span>:</span></span><br><span class="line">	prime_num = []</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> range(m,n+<span class="number">1</span>):</span><br><span class="line">		<span class="keyword">if</span> isprime(i):</span><br><span class="line">			prime_num.append(i)</span><br><span class="line">	<span class="keyword">return</span> prime_num</span><br><span class="line"></span><br><span class="line">m = int(input(<span class="string">'please input m:'</span>))</span><br><span class="line">n = int(input(<span class="string">'please input n:'</span>))</span><br><span class="line">print(prime_m2n(m,n))</span><br></pre></td></tr></tbody></table></figure>

<p>练习：利用切片操作实现一个 trim()函数，去除字符串首尾的空格，注意不要调用str的strip()的方法</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">trim</span><span class="params">(s)</span>:</span></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> s[:]:</span><br><span class="line">		<span class="keyword">if</span> i == <span class="string">' '</span>:</span><br><span class="line">			s = s[<span class="number">1</span>:]</span><br><span class="line">		<span class="keyword">else</span>:</span><br><span class="line">			<span class="keyword">break</span></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> s[::<span class="number">-1</span>]:</span><br><span class="line">		<span class="keyword">if</span> i == <span class="string">' '</span>:</span><br><span class="line">			s = s[:<span class="number">-1</span>]</span><br><span class="line">		<span class="keyword">else</span>:</span><br><span class="line">			<span class="keyword">break</span></span><br><span class="line">	retutn s</span><br><span class="line">a = <span class="string">'    hello  word    '</span></span><br><span class="line">print(trim(a))</span><br><span class="line"><span class="keyword">if</span> trim(a) == <span class="string">'hello word'</span>:</span><br><span class="line">	print(<span class="string">'测试成功'</span>)</span><br></pre></td></tr></tbody></table></figure>

<hr>
<h1 id="面向对象编程（oop）"><a href="#面向对象编程（oop）" class="headerlink" title="面向对象编程（oop）"></a>面向对象编程（oop）</h1><ul>
<li>oop 是为了代码重用</li>
<li>可以用一个类来产生多个实例对象</li>
<li>什么是面向对象：一切皆对象，对象和对象之间有关联关系</li>
</ul>
<ul>
<li>图纸 -> 类class</li>
<li>具体的某辆车 -> 对象(object)/实例(insyance)</li>
<li>人(类) -> 张三(实例对象)  #想要创建实例对象，先要创建类</li>
</ul>
<h2 id="类的创建语法："><a href="#类的创建语法：" class="headerlink" title="类的创建语法："></a>类的创建语法：</h2><figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[@类装饰器]</span><br><span class="line">class 类名(继承列表)：</span><br><span class="line">	“类文件字符串”</span><br><span class="line">	实例方法 （内类的函数方法叫method）定义</span><br><span class="line">	类变量定义</span><br></pre></td></tr></tbody></table></figure>

<p>最简单的类：</p>
<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">class DOg:</span><br><span class="line">	pass</span><br></pre></td></tr></tbody></table></figure>

<h2 id="类的作用："><a href="#类的作用：" class="headerlink" title="类的作用："></a>类的作用：</h2><ol>
<li><p>定义一个类，可以用来创建实例对象</p>
</li>
<li><p>类内定义的变量和方法能被比此类所创建的实例所共同拥有</p>
</li>
<li><p>类通常用来创建具有共同属性的对象</p>
<p> （如果只是创建了一个对象，用模块就可以，不必用类）</p>
</li>
</ol>
<h2 id="实例创建表达式："><a href="#实例创建表达式：" class="headerlink" title="实例创建表达式："></a>实例创建表达式：</h2><blockquote>
<p>实例名 = 类名(创建传参)</p>
</blockquote>
<p>作用：</p>
<blockquote>
<p>创建一个类的实例对象并返回此实例</p>
</blockquote>
<p>实例说明：</p>
<ol>
<li>实例有自己的作用域和名字空间，可以为该实例添加变量(实例变量/实例属性)</li>
<li>实例可以调用类的方法</li>
<li>实例可以间接的访问类中的变量</li>
</ol>
<h2 id="实例变量的调用语法："><a href="#实例变量的调用语法：" class="headerlink" title="实例变量的调用语法："></a>实例变量的调用语法：</h2><blockquote>
<p>实例.变量名</p>
</blockquote>
<h2 id="点在模块中的用法："><a href="#点在模块中的用法：" class="headerlink" title="点在模块中的用法："></a>点在模块中的用法：</h2><ul>
<li>模块.变量名</li>
<li>模块.函数名</li>
<li>模块.类名</li>
</ul>
<h2 id="实例变量的赋值规则："><a href="#实例变量的赋值规则：" class="headerlink" title="实例变量的赋值规则："></a>实例变量的赋值规则：</h2><ol>
<li>首次赋值则创建实例变量</li>
<li>再次赋值则改变实例变量的绑定关系</li>
</ol>
<h2 id="实例的方法："><a href="#实例的方法：" class="headerlink" title="实例的方法："></a>实例的方法：</h2><p>语法：</p>
<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">class 类名（传承列表）:</span><br><span class="line">	def 实例方法名(self,参数1，参数2...):</span><br><span class="line">	"文档字符串"</span><br><span class="line">	语句块</span><br><span class="line">(self是指实例自己)</span><br></pre></td></tr></tbody></table></figure>

<h2 id="实例方法的调用语法："><a href="#实例方法的调用语法：" class="headerlink" title="实例方法的调用语法："></a>实例方法的调用语法：</h2><ul>
<li>实例.实例方法名(调用参数)        #常用方法</li>
</ul>
<p>或</p>
<ul>
<li>类名.实例方法名(实例，调用参数)</li>
</ul>
<p>说明:</p>
<ol>
<li>实例方法的实质就是函数，是定义在类内的函数</li>
<li>实例方法属于类属性</li>
<li>实例方法的第一个参数代表调用这个方法的实例，一般命名为‘self‘</li>
<li>实例方法如果没有 return 语句，则返回 none<blockquote>
<p>例子：dog.py</p>
</blockquote>
</li>
</ol>
<hr>
<p>#DAY4</p>
<h2 id="构造方法"><a href="#构造方法" class="headerlink" title="构造方法:"></a>构造方法:</h2><h3 id="作用："><a href="#作用：" class="headerlink" title="作用："></a>作用：</h3><blockquote>
<p>创建对象时初始化实例变量:</p>
<p>(建立给每个对象传参共同方式，及初始化对象的属性)</p>
</blockquote>
<h3 id="语法："><a href="#语法：" class="headerlink" title="语法："></a>语法：</h3><blockquote>
<p>def <strong>inint</strong> (self [,参数列表]):</p>
<pre><code>语句块</code></pre></blockquote>
<p>说明：</p>
<blockquote>
<ul>
<li>构造方法必须为<strong>int</strong>,不可改变</li>
<li>在一个类中只能有一个_int_构造方法（有多个时，最后一个起作用）</li>
<li>构造方法会在实例生成式自动调用，且将实例自身通过第一个参数self 传入 <strong>int</strong>方法</li>
<li>构造方法如果没有return语句，则返回self本身。</li>
</ul>
</blockquote>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">car</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span> <span class="params">(self, color, brand, model)</span>:</span></span><br><span class="line">        self.brand = brand</span><br><span class="line">        self.model = model</span><br><span class="line">        self.color = color</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">run</span><span class="params">(self, speed)</span>:</span></span><br><span class="line">        print(self.color, self.brand, self.model,\</span><br><span class="line">            <span class="string">'正在以'</span>, speed, <span class="string">'KM/h速度行驶'</span>)</span><br><span class="line">        t = (self.color, self.brand, self.model, speed)</span><br><span class="line">        fmt = <span class="string">'%s%s%s正在以%dkm/h行驶'</span> %t    <span class="comment">#格式化字符串</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">change_color</span><span class="params">(self, c)</span>:</span></span><br><span class="line">        self.color = c</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">infos</span><span class="params">(self)</span>:</span></span><br><span class="line">        print(<span class="string">'车辆信息为：'</span>, self.brand, self.model, self.color)</span><br><span class="line"></span><br><span class="line">a4 = car(<span class="string">'红色'</span>,<span class="string">'奥迪'</span>,<span class="string">'A4'</span>)</span><br><span class="line">a4.run(<span class="number">199</span>)</span><br><span class="line">a4.change_color(<span class="string">'黑色'</span>)</span><br><span class="line">a4.run(<span class="number">230</span>)</span><br><span class="line">a4.infos()</span><br><span class="line">print(a4.color)</span><br></pre></td></tr></tbody></table></figure>

<blockquote>
<p>在oop程序设计当中，当我们定义一个class时侯，可以从某个现有的class类继承，新的class称为子类（subclass），而被继承的class称为基类，父类或超类（Base class,Supper class）.子类可以继承父类的方法</p>
</blockquote>
<h3 id="比如：我们已经编写了一个名为Animal的class、有一个run（）的方法可以直接打印："><a href="#比如：我们已经编写了一个名为Animal的class、有一个run（）的方法可以直接打印：" class="headerlink" title="比如：我们已经编写了一个名为Animal的class、有一个run（）的方法可以直接打印："></a>比如：我们已经编写了一个名为Animal的class、有一个run（）的方法可以直接打印：</h3><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Animal</span><span class="params">(object)</span>:</span></span><br><span class="line">	<span class="function"><span class="keyword">def</span> <span class="title">run</span><span class="params">(self)</span>:</span></span><br><span class="line">		print(<span class="string">'Animal is running'</span>)</span><br><span class="line">a = Animal()</span><br><span class="line">a.run</span><br></pre></td></tr></tbody></table></figure>

<h3 id="当我们需要编写Dog类和Cat类时，就可以之接从Animsl类继承"><a href="#当我们需要编写Dog类和Cat类时，就可以之接从Animsl类继承" class="headerlink" title="当我们需要编写Dog类和Cat类时，就可以之接从Animsl类继承"></a>当我们需要编写Dog类和Cat类时，就可以之接从Animsl类继承</h3><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Dog</span><span class="params">(Animal)</span>:</span></span><br><span class="line">	<span class="function"><span class="keyword">def</span> <span class="title">run</span><span class="params">(self)</span>:</span></span><br><span class="line">		print(<span class="string">'Dog is running....'</span>)</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">def</span> <span class="title">Cat</span><span class="params">(self)</span>:</span></span><br><span class="line">		print(<span class="string">'Eating meat....'</span>)</span><br><span class="line"></span><br><span class="line">Class Cat(Animal):</span><br><span class="line">	pss</span><br></pre></td></tr></tbody></table></figure>

<p>对于Dog类来说，Animal就是父类，对于Animal来说，Dog就是他是子类。Cat类和Dog类同理。</p>
<h3 id="继承有什么好处？"><a href="#继承有什么好处？" class="headerlink" title="继承有什么好处？"></a>继承有什么好处？</h3><p>做大的好处就是子类获得了父类的全部功能。由于Animal实现了run()方法，因此，Dog和Cat作为他的子类，即使没什么事干，它自动拥有了run()的方法。</p>
<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Dog = Dog()</span><br><span class="line">dog.run()</span><br><span class="line"></span><br><span class="line">cat = Cat()</span><br><span class="line">cat.run()</span><br></pre></td></tr></tbody></table></figure>

<p>当子类和父类都在相同的run()方法时，我们说，子类的run()覆盖了父类的run(),在代码运行的时候，总是会调用子类的run().这样，我们就获得了继承的另一个好处：多态。</p>
<p>在继承关系中，如果只是一个实例的数据类型是某个子类，呢么他的数据类型也可以被看作是父类</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Human</span>:</span></span><br><span class="line">	<span class="function"><span class="keyword">def</span> <span class="title">say</span><span class="params">(self, what)</span>:</span></span><br><span class="line">		print(<span class="string">'say:'</span>, what)</span><br><span class="line">	</span><br><span class="line">	<span class="function"><span class="keyword">def</span> <span class="title">run</span><span class="params">(self, speed)</span>:</span></span><br><span class="line">		print(<span class="string">'run....'</span>, speed)</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Student</span><span class="params">(Human)</span>:</span></span><br><span class="line">	<span class="function"><span class="keyword">def</span> <span class="title">study</span><span class="params">(self, program)</span>:</span></span><br><span class="line">		print(<span class="string">'learing'</span>, program)</span><br><span class="line"></span><br><span class="line">h1 = human()</span><br><span class="line">h1.run(<span class="number">5</span>)</span><br><span class="line">h1.say(<span class="string">'good weather!'</span>)</span><br><span class="line"></span><br><span class="line">s1 = Student()</span><br><span class="line">s1.run(<span class="number">10</span>)</span><br><span class="line">s1.say(<span class="string">'good'</span>, day)</span><br><span class="line">s1.study(<span class="string">'python'</span>)</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Teacher</span><span class="params">(human)</span>:</span></span><br><span class="line">	<span class="function"><span class="keyword">def</span> <span class="title">teach</span><span class="params">(self, language)</span>:</span></span><br><span class="line">		print(<span class="string">'teaching'</span>, language)</span><br><span class="line"></span><br><span class="line">t1 = Teacher()</span><br><span class="line">t1.run(<span class="number">6</span>)</span><br><span class="line">t1.say(<span class="string">'home work is'</span>)</span><br><span class="line">t1.teach(<span class="string">'python'</span>)</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">class Bicycle:</span><br><span class="line">	def Run(self, Km):</span><br><span class="line">	print('自行车骑行了'. km, '公里')</span><br><span class="line"></span><br><span class="line">class EBicycle(Bicycle):</span><br><span class="line">	def __init__ (self, vol):</span><br><span class="line">	self.max_volume = vol</span><br><span class="line">	self.cur_voume = vol</span><br><span class="line"></span><br><span class="line"># 每骑行10km消耗电量1度， 同时显示当前电量</span><br><span class="line">	def Run (self, KM):</span><br><span class="line">		v = min(KM/10,self.cur_volume) # min(), 求参数中最小值</span><br><span class="line">		self.cur_volume -= v</span><br><span class="line">		print('电动车骑行了%d km' % (v*10))</span><br><span class="line">		print('电动车剩余电量：'， self.cur_volume)</span><br><span class="line"></span><br><span class="line">def fillcharge(self):</span><br><span class="line">	print('正在充电')</span><br><span class="line">	self，cur_volume = self.max_volume</span><br><span class="line"></span><br><span class="line">b = EBicycle(5)</span><br><span class="line">b.Run(10)</span><br><span class="line">b.Run(1000)</span><br><span class="line">b.fillcharge()</span><br></pre></td></tr></tbody></table></figure>

<h1 id="封装"><a href="#封装" class="headerlink" title="封装"></a>封装</h1><p>封装指隐藏类的实现细节，让使用者不关心这些细节</p>
<p>python的封装是假的（模拟的）封装</p>
<p>python以双下划线开头，不以下划线结尾的实例变量为类的私有变量，在子类中无法使用。</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Father</span>:</span></span><br><span class="line">	<span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></span><br><span class="line">		print(<span class="string">'A::__init__'</span>)</span><br><span class="line">		self.__money = <span class="number">10000</span></span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">def</span> <span class="title">makemoney</span><span class="params">(self,m)</span>:</span></span><br><span class="line">		self.__money += m</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">def</span> <span class="title">moneys</span><span class="params">(self)</span>:</span></span><br><span class="line">		print(self.__money)</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">B</span><span class="params">(Father)</span>:</span></span><br><span class="line">	<span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></span><br><span class="line">		super() .__init__()</span><br><span class="line">	<span class="function"><span class="keyword">def</span> <span class="title">show_money</span><span class="params">(self)</span>:</span></span><br><span class="line">		<span class="comment"># print(self.__money)</span></span><br><span class="line">		print(self._Father__money)</span><br><span class="line"></span><br><span class="line">b = B()</span><br><span class="line">b.makemoney(<span class="number">2000</span>)</span><br><span class="line">b.moneys()</span><br><span class="line">b.show_money()</span><br></pre></td></tr></tbody></table></figure>

<h1 id="模块"><a href="#模块" class="headerlink" title="模块"></a>模块</h1><h3 id="什么是模块："><a href="#什么是模块：" class="headerlink" title="什么是模块："></a>什么是模块：</h3><pre><code>模块是一个包含1个或多个函数，变量，类等组成的程序组
模块文件通常以.py结尾</code></pre><h3 id="模块的作用："><a href="#模块的作用：" class="headerlink" title="模块的作用："></a>模块的作用：</h3><pre><code>1.让一些相关的变量，函数，类等有逻辑的组织在一起
2.让逻辑解构更加清晰
3.模块中的函数和类等可提供给其他模块或程序使用</code></pre><h3 id="模块的分类："><a href="#模块的分类：" class="headerlink" title="模块的分类："></a>模块的分类：</h3><pre><code>1.内置模块（builtins）,在解析器内部可以直接使用
2.标准库模块，python安装时已经标配
3.第三方模块（通常为开源），需要自己安装
4.用户自己编写的模块（也可以作为其他人的第三方模块）</code></pre><h3 id="为什么使用模块"><a href="#为什么使用模块" class="headerlink" title="为什么使用模块"></a>为什么使用模块</h3><pre><code>1.代码复用
2.系统命名空间的划分(避免变量冲突)
3.实现共享服务和共享数据（一个模块被多个函数或文件导入）</code></pre><h3 id="如何组织一个程序："><a href="#如何组织一个程序：" class="headerlink" title="如何组织一个程序："></a>如何组织一个程序：</h3><pre><code>1.一个python程序包含了多个含有python语句的文本文件。顶层文件和多个支持文件构成
2.顶层文件（又被称脚本）包含了程序的主要控制流程（启动应用的文件）
3.模块文件就是工具的库，顶层文件使用模块文件中定义的工具，而这些模块使用了其他模块所定义的工具
4.在python中，一个文件导入了一个模块来获得这个模块定义的工具的访问权，这些工具被认作是这个模块的属性。</code></pre><h3 id="模块的导入"><a href="#模块的导入" class="headerlink" title="模块的导入:"></a>模块的导入:</h3><blockquote>
<p>import 模块名1 [as 模块新名1][, 模块名2]</p>
<p>import 模块名</p>
<p>import 模块名 as 新名</p>
</blockquote>
<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">import math</span><br><span class="line">print(math.sqrt(9))</span><br><span class="line"></span><br><span class="line">math = 2.7   ####不要用模块当变量名</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">import math as m</span><br><span class="line">print(m.factorial(5))   ##阶乘</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">from 模块名 import 模块属性 as 新名</span><br><span class="line">(这种方法导入后，可直接使用模块中的属性，不需要再写模块名)</span><br><span class="line"></span><br><span class="line">from 模块名 import *</span><br><span class="line"></span><br><span class="line">from math import factorial as fac</span><br><span class="line">print(fac(5))</span><br><span class="line"></span><br><span class="line">from math import pi</span><br><span class="line">print(pi)</span><br><span class="line">print(sin(pi/2))</span><br><span class="line"></span><br><span class="line">from math import *</span><br></pre></td></tr></tbody></table></figure>

<h4 id="数学模块-math"><a href="#数学模块-math" class="headerlink" title="数学模块    math:"></a>数学模块    math:</h4><h5 id="变量："><a href="#变量：" class="headerlink" title="变量："></a>变量：</h5><table>
<thead>
<tr>
<th>变量</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>math.e</td>
<td>自然对数</td>
</tr>
<tr>
<td>math.pi</td>
<td>圆周率</td>
</tr>
<tr>
<td>##### 函数：</td>
<td></td>
</tr>
<tr>
<td>函数</td>
<td>含义</td>
</tr>
<tr>
<td>—</td>
<td>—</td>
</tr>
<tr>
<td>math.floor(x)</td>
<td>对x向下取整 x=1.2 返回1</td>
</tr>
<tr>
<td>math.ceil(x)</td>
<td>对x向上取整 x=1.2 返回2</td>
</tr>
<tr>
<td>math.sqrt(x)</td>
<td>返回x的平方根</td>
</tr>
<tr>
<td>math.factorial(x)</td>
<td>求x的阶乘</td>
</tr>
<tr>
<td>math.log(x[,base])</td>
<td>放回以base为底的对数，如果不给出base则以e为底</td>
</tr>
<tr>
<td>math.log10(x)</td>
<td>求10为底的对数</td>
</tr>
<tr>
<td>math.pow(x,y)</td>
<td>返回x**y</td>
</tr>
<tr>
<td>math.fabs(x)</td>
<td>返回浮点数x的绝对值</td>
</tr>
<tr>
<td>math.degress(x)</td>
<td>将弧度转换为角度</td>
</tr>
<tr>
<td>math.radians(x)</td>
<td>将角度转换为弧度</td>
</tr>
<tr>
<td>math.sin(x)</td>
<td>x正弦</td>
</tr>
<tr>
<td>math.cos(x)</td>
<td>x的余弦</td>
</tr>
<tr>
<td>math.tan(x)</td>
<td>x的正切</td>
</tr>
<tr>
<td>math.asin(x)</td>
<td>返回x的反正弦</td>
</tr>
<tr>
<td>math.acos(x)</td>
<td>返回x的反余弦</td>
</tr>
<tr>
<td>math.atan(x)</td>
<td>返回x的反正切</td>
</tr>
</tbody></table>
<h4 id="时间模块-time"><a href="#时间模块-time" class="headerlink" title="时间模块 time"></a>时间模块 time</h4><p>使用方法：</p>
<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">import time</span><br><span class="line">from time import *</span><br><span class="line">from time import sleep</span><br><span class="line"></span><br><span class="line">time.sleep(seconds)</span><br><span class="line"></span><br><span class="line">from time import *</span><br><span class="line">L = [1,2,3]</span><br><span class="line">for i in L:</span><br><span class="line">	L.append(L)</span><br><span class="line">	sleep(L)</span><br><span class="line">	print(L)</span><br></pre></td></tr></tbody></table></figure>

<p>多次导入一个模块时，模块对应的.py文件不会多次执行</p>
<p>模块只执行一次,py程序</p>
<h4 id="模块路径的搜索顺序："><a href="#模块路径的搜索顺序：" class="headerlink" title="模块路径的搜索顺序："></a>模块路径的搜索顺序：</h4><figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">import  模块名  #去哪找这个模块</span><br><span class="line">1.搜索内置模块（用c语言写的内置在python程序中的模块，无法用路径找到）</span><br><span class="line">2.标准库路径（如：sys, os）</span><br><span class="line">3.sys.path提供的路径</span><br><span class="line">  sys.path是一个表，里面放的都是模块搜索路径</span><br><span class="line">4.搜索程序运行的路径（当前路径）</span><br></pre></td></tr></tbody></table></figure>

<ul>
<li>import dir.dir2..mod            (dir0\dir1\dir2\mod,py)</li>
</ul>
<ol>
<li>dir1和dir2中必须都含有一个<strong>init</strong>.py文件</li>
<li>dir0是容器，不需要<strong>init</strong>.py文件，如果有的话，这个文件会被忽略</li>
<li>dir0必须列在模块的搜索路径上（也就是此目录必须为主目录，或者在PYTHONPATH中）</li>
</ol>
<ul>
<li><strong>init</strong>.py可以包含python程序代码（比如print语句），也可以完全是空的。作为一个高级功能，可以在<strong>init</strong>.py文件中使用<strong>all</strong>列表来定义目录，</li>
<li>当以from … import * 导入时，来定义需要导入什么。</li>
<li><strong>all</strong> = [‘super’,’tank’,’contra’]</li>
</ul>
<hr>
<p>某次战役中，为方便信息交互，我军侦察部门将此次的关键高地坐标设定为（x = 0,y = 0），并规定，没向东增加100米，x加1，向北增加100米，y加一，同时我军情报部门也破译了敌军向坦克发送的指挥信号，其中有三种信号（L,R,M）用于控制坦克运动，L和R分别表示向左、向右转向，M标识零坦克前进100米，其他信号如T时间同步，P用于位置校准（T，P不会控制坦克移动）</p>
<p>一日我军侦察兵发现了敌军的一辆坦克，侦察兵立即将坦克的坐标（P，Q）及坦克前进方向（W，E，N，S）发送给指挥部，同时启动信号接收器，将坦克接受的信号实时同步发往指挥部，指挥部用过信息计算出坦克位置，并击毁该坦克</p>
<ul>
<li><p>请设计程序计算出坦克所在位置。</p>
</li>
<li><p>（P=11，Q=39）      初始朝向：W</p>
</li>
<li><p>infor = ‘MTMPRPMTMLMRPMTPLMMTLMRRMP’</p>
</li>
<li><p>L = [1,2,3,4,5]</p>
</li>
<li><p>i = L.index(3)     # 查找索引</p>
</li>
<li><p>print（i）          #  2</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">direction = <span class="string">'W'</span></span><br><span class="line">p = <span class="number">11</span></span><br><span class="line">q = <span class="number">39</span></span><br><span class="line">infor = <span class="string">'MTMPRPMTMLMRPMTPLMMTLMRRMP'</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">cal_direction</span><span class="params">(turn)</span>:</span></span><br><span class="line">	D = [<span class="string">'E'</span>, <span class="string">'S'</span>, <span class="string">'W'</span>, <span class="string">'N'</span>]</span><br><span class="line">	i = D.index(direction)</span><br><span class="line">	<span class="keyword">if</span> turn == <span class="string">'L'</span>:</span><br><span class="line">		i = i - <span class="number">1</span></span><br><span class="line">	<span class="keyword">if</span> turn == <span class="string">'R'</span>:</span><br><span class="line">		i = i + <span class="number">1</span></span><br><span class="line">	<span class="keyword">if</span> i == len(D):</span><br><span class="line">		i = <span class="number">0</span></span><br><span class="line">	<span class="keyword">return</span> D[i]</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">cal_move</span><span class="params">(p,q)</span>:</span></span><br><span class="line">	<span class="keyword">if</span> direction == <span class="string">'E'</span>:</span><br><span class="line">		p = p + <span class="number">1</span></span><br><span class="line">	<span class="keyword">elif</span> direction == <span class="string">'N'</span>:</span><br><span class="line">		q = q + <span class="number">1</span></span><br><span class="line">	<span class="keyword">elif</span> direction == <span class="string">'W'</span>:</span><br><span class="line">		p = p - <span class="number">1</span></span><br><span class="line">	<span class="keyword">elif</span> direction == <span class="string">'S'</span>:</span><br><span class="line">		q = q - <span class="number">1</span></span><br><span class="line">	<span class="keyword">return</span> p, q</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> infor</span><br><span class="line">	<span class="keyword">if</span> i == <span class="string">'L'</span> <span class="keyword">or</span> i == <span class="string">'R'</span>:</span><br><span class="line">		direction = cal_direction</span><br><span class="line">	<span class="keyword">if</span> i == <span class="string">'M'</span>:</span><br><span class="line">		p,q = cal_move(p,q)</span><br><span class="line"></span><br><span class="line">print((p,q),direction)</span><br></pre></td></tr></tbody></table></figure>

</li>
</ul>
<hr>
<h1 id="DAY5"><a href="#DAY5" class="headerlink" title="DAY5"></a>DAY5</h1><h2 id="飞机大战游戏"><a href="#飞机大战游戏" class="headerlink" title="飞机大战游戏"></a>飞机大战游戏</h2><h2 id="设计思路："><a href="#设计思路：" class="headerlink" title="设计思路："></a>设计思路：</h2><p>1.游戏中的几种对象？</p>
<ul>
<li>敌机    蜜蜂   子弹   战机</li>
</ul>
<p>2.考虑游戏有几种状态？</p>
<ul>
<li>开始   运行   游戏结束</li>
</ul>
<p>3.考虑敌机怎么移动？英雄机怎么移动？蜜蜂子弹怎么移动？</p>
<ul>
<li>敌机下降（y坐标+）</li>
<li>战机：随鼠标移动（鼠标在图片中心）</li>
<li>子弹：直线上升，从战机所在位置发出</li>
<li>蜜蜂：先向右下，到右边界之后转向左下</li>
</ul>
<h2 id="游戏组成："><a href="#游戏组成：" class="headerlink" title="游戏组成："></a>游戏组成：</h2><p>1.窗体  面板  子弹  敌机  战机  蜜蜂</p>
<p>2.自己的飞机和敌人的飞机</p>
<p>3.飞机动起来</p>
<p>4.互相打</p>
<h2 id="业务需求："><a href="#业务需求：" class="headerlink" title="业务需求："></a>业务需求：</h2><p>1.打死敌机+5分</p>
<p>2.打死蜜蜂：奖励生命值或双倍火力</p>
<p>3.战机和敌机碰撞后：生命-1</p>
<p>4.双倍火力：发一次子弹双倍火力子弹-2</p>
<h2 id="设计模型："><a href="#设计模型：" class="headerlink" title="设计模型："></a>设计模型：</h2><p>1.战机，敌机，蜜蜂，子弹，分数，生命值，都是矩形框</p>
<p>2.坐标：以矩形框的左上角为依据</p>
<hr>
<h2 id="让tkinter-GUI-程序启动和运行起来需要五个步骤"><a href="#让tkinter-GUI-程序启动和运行起来需要五个步骤" class="headerlink" title="让tkinter GUI 程序启动和运行起来需要五个步骤"></a>让tkinter GUI 程序启动和运行起来需要五个步骤</h2><p>1.导入tkinter模块</p>
<blockquote>
<p>import tkinter</p>
</blockquote>
<p>2.创建一个空白窗口对象，用于容纳整个GUI应用</p>
<p>3.在空白窗口对象上构建所有的GUI组件及功能</p>
<p>4.通过底层的应用代码将这些GUI组件间接起来</p>
<p>5.进入主事件循环</p>
<hr>
<h1 id="DAY3-1"><a href="#DAY3-1" class="headerlink" title="DAY3"></a>DAY3</h1><p>请写一段python代码实现删除一个list里面重复的元素</p>
<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">L = [1,2,2,7,3,5,7,5,3,2]</span><br><span class="line">print(list(set(L)))     # 因为集合是无序的</span><br></pre></td></tr></tbody></table></figure>

<p>不需使用set</p>
<figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">L3 = []</span><br><span class="line">j = 0</span><br><span class="line"></span><br><span class="line">for i in L:</span><br><span class="line">	if i not inL[:j]:</span><br><span class="line">		L3.append(i)</span><br><span class="line">	j = j + 1</span><br><span class="line"></span><br><span class="line">print(L3,'L3')</span><br></pre></td></tr></tbody></table></figure>

<h2 id="python里如何拷贝一个对象？（赋值，浅拷贝，深拷贝的区别）"><a href="#python里如何拷贝一个对象？（赋值，浅拷贝，深拷贝的区别）" class="headerlink" title="python里如何拷贝一个对象？（赋值，浅拷贝，深拷贝的区别）"></a>python里如何拷贝一个对象？（赋值，浅拷贝，深拷贝的区别）</h2><ul>
<li>a = 3</li>
<li>b = a</li>
</ul>
<h2 id="浅拷贝（copy）：拷贝父对象，不会拷贝对象内部的子对象"><a href="#浅拷贝（copy）：拷贝父对象，不会拷贝对象内部的子对象" class="headerlink" title="浅拷贝（copy）：拷贝父对象，不会拷贝对象内部的子对象"></a>浅拷贝（copy）：拷贝父对象，不会拷贝对象内部的子对象</h2><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">a = {<span class="number">1</span>:[,<span class="number">2</span>,<span class="number">3</span>]}</span><br><span class="line">b = a.cpopy()</span><br><span class="line">print(b)</span><br><span class="line">a[<span class="number">1</span>].append(<span class="number">4</span>)</span><br><span class="line">print(a)</span><br><span class="line">print(b)</span><br></pre></td></tr></tbody></table></figure>

<h2 id="深拷贝（deecopy）-copy模块的deepcopy方法，完全拷贝了父对象及其子对象"><a href="#深拷贝（deecopy）-copy模块的deepcopy方法，完全拷贝了父对象及其子对象" class="headerlink" title="深拷贝（deecopy）:copy模块的deepcopy方法，完全拷贝了父对象及其子对象"></a>深拷贝（deecopy）:copy模块的deepcopy方法，完全拷贝了父对象及其子对象</h2><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> copy</span><br><span class="line">c = copy.deepcopy(a)</span><br><span class="line">print(a,c)</span><br><span class="line">a[<span class="number">1</span>].append(<span class="number">5</span>)</span><br><span class="line">print(<span class="string">'a'</span>,a)</span><br><span class="line">print(<span class="string">'c'</span>,c)</span><br></pre></td></tr></tbody></table></figure>

<h2 id="二分查找"><a href="#二分查找" class="headerlink" title="二分查找"></a>二分查找</h2><h3 id="必须是有序的数列"><a href="#必须是有序的数列" class="headerlink" title="必须是有序的数列"></a>必须是有序的数列</h3><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> random</span><br><span class="line">L = [<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>,<span class="number">12</span>,<span class="number">34</span>,<span class="number">89</span>,<span class="number">99</span>]</span><br><span class="line">guess = L[random.randint(<span class="number">0</span>,len(L)<span class="number">-1</span>)]       <span class="comment"># L[]</span></span><br><span class="line">print(guess)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">dich</span><span class="params">(L)</span>:</span></span><br><span class="line">	low = <span class="number">0</span></span><br><span class="line">	heigh = len(L) - <span class="number">1</span></span><br><span class="line">	<span class="keyword">while</span> low <= heigh:<="" span=""><br><span class="line">	mid = (low + heigh)//<span class="number">2</span></span><br><span class="line">	<span class="keyword">if</span> L[mid] == guess:</span><br><span class="line">		print(<span class="string">'猜对了，是%s'</span> % L [mid])</span><br><span class="line">		<span class="keyword">return</span> L[mid]</span><br><span class="line">	<span class="keyword">if</span> L[mid] < guess:</span><br><span class="line">		print(<span class="string">'猜小了，%s'</span> % L [mid])</span><br><span class="line">		low = mid + <span class="number">1</span></span><br><span class="line">	<span class="keyword">if</span> L[mid] > guess:</span><br><span class="line">	print(<span class="string">'猜大了，%s'</span> % L [mid])</span><br><span class="line">	heigh = mid - <span class="number">1</span></span><br></=></span></pre></td></tr></tbody></table></figure>

<h2 id="快速排序：-递归"><a href="#快速排序：-递归" class="headerlink" title="快速排序：         #递归"></a>快速排序：         #递归</h2><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">L = [<span class="number">5</span>,<span class="number">4</span>,<span class="number">7</span>,<span class="number">3</span>,<span class="number">9</span>,<span class="number">2</span>,<span class="number">10</span>,<span class="number">11</span>,<span class="number">1</span>]</span><br><span class="line">target = <span class="number">5</span></span><br><span class="line">	[<span class="number">4</span>,<span class="number">3</span>,<span class="number">2</span>,<span class="number">1</span>,<span class="number">5</span>,<span class="number">7</span>,<span class="number">9</span>,<span class="number">10</span>,<span class="number">11</span>]</span><br><span class="line">	[<span class="number">4</span>,<span class="number">3</span>,<span class="number">2</span>,<span class="number">1</span>][<span class="number">5</span>][<span class="number">7</span>,<span class="number">9</span>,<span class="number">10</span>,<span class="number">11</span>]</span><br><span class="line"></span><br><span class="line">L = [<span class="number">5</span>,<span class="number">4</span>,<span class="number">7</span>,<span class="number">3</span>,<span class="number">9</span>,<span class="number">2</span>,<span class="number">10</span>,<span class="number">11</span>,<span class="number">1</span>]</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">quickSort</span><span class="params">(L)</span></span></span><br><span class="line">	if len(L) <= 1:<="" span=""><br><span class="line">		<span class="keyword">return</span> L</span><br><span class="line">	<span class="keyword">else</span>:</span><br><span class="line">		target = L[<span class="number">0</span>]</span><br><span class="line">		smaller = [i <span class="keyword">for</span> i <span class="keyword">in</span> L[<span class="number">1</span>:] <span class="keyword">if</span> i < target]</span><br><span class="line">		bigger = [i <span class="keyword">for</span> i <span class="keyword">in</span> L[<span class="number">1</span>:] <span class="keyword">if</span> i >= target]</span><br><span class="line">		<span class="keyword">return</span> quickSort(smaller)+[target]+quickSort(bigger)</span><br><span class="line">print(quickSort(L))</span><br></=></span></pre></td></tr></tbody></table></figure>

<p>三张支票，100万，其中一张是真的，两张是假的。让你选一张，主持人会帮你从剩下的两张中，拿出一张，并告诉你这张是假的。此时，主持人会问你是否坚持原来的选择，还是更换选择。</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> random</span><br><span class="line"></span><br><span class="line">times = int(input(<span class="string">'请输入测试次数：'</span>))</span><br><span class="line">L = [<span class="number">0</span>,<span class="number">1</span>,<span class="number">2</span>]</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">guess_ch</span><span class="params">()</span>:</span></span><br><span class="line">	real = random.randint(<span class="number">0</span>,<span class="number">2</span>)</span><br><span class="line">	L2 = L[:]</span><br><span class="line">	choice_1 = random.randint(<span class="number">0</span>,<span class="number">2</span>)</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> L2:</span><br><span class="line">	<span class="keyword">if</span> i != real <span class="keyword">and</span> i != choise_1:</span><br><span class="line">		L2.pop(L2.inde(i))</span><br><span class="line">		<span class="keyword">break</span></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> L2:</span><br><span class="line">		<span class="keyword">if</span> i != choicd_1:</span><br><span class="line">			<span class="keyword">if</span> i == real:</span><br><span class="line">				<span class="keyword">return</span> <span class="keyword">True</span></span><br><span class="line">			<span class="keyword">else</span>:</span><br><span class="line">				<span class="keyword">return</span> Flase</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">guess_notch</span><span class="params">()</span>:</span></span><br><span class="line">	real = random.randint(<span class="number">0</span>,<span class="number">2</span>)</span><br><span class="line">	L2 = L[:]</span><br><span class="line">	choice_1 = random.randint(<span class="number">0</span>,<span class="number">2</span>)</span><br><span class="line">	<span class="keyword">if</span> choice_1 == real:</span><br><span class="line">		<span class="keyword">return</span> <span class="keyword">True</span></span><br><span class="line">	<span class="keyword">else</span>:</span><br><span class="line">		<span class="keyword">return</span> Flase</span><br><span class="line">right_1 = <span class="number">0</span></span><br><span class="line">wrong_1 = <span class="number">0</span></span><br><span class="line">right_2 = <span class="number">0</span></span><br><span class="line">wrong_2 = <span class="number">0</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> range(time):</span><br><span class="line">	<span class="keyword">if</span> guess_ch():</span><br><span class="line">		right_1 += <span class="number">1</span></span><br><span class="line">	<span class="keyword">else</span>:</span><br><span class="line">		wrong_1 += <span class="number">1</span></span><br><span class="line">	<span class="keyword">if</span> guess_notch():</span><br><span class="line">		right_2 += <span class="number">1</span></span><br><span class="line">	<span class="keyword">else</span>:</span><br><span class="line">		wrong_2 += <span class="number">1</span></span><br><span class="line">print(<span class="string">'更改选择：'</span>)</span><br><span class="line">print(<span class="string">'猜正确的次数为%d次'</span>% right_1)</span><br><span class="line">print(<span class="string">'正确率：'</span>,right_1/times)</span><br><span class="line">print(<span class="string">'不更改选择：'</span>)</span><br><span class="line">print(<span class="string">'猜正确的次数为%d次'</span>% right_2)</span><br><span class="line">print(<span class="string">'正确率：'</span>,right_2/times)</span><br></pre></td></tr></tbody></table></figure>

<p>小白鼠</p>
<figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> random </span><br><span class="line"></span><br><span class="line">poison_bottle = random.randint(<span class="number">1</span>,<span class="number">1000</span>)</span><br><span class="line">find_bottle = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">M = {x:[] <span class="keyword">for</span> x <span class="keyword">in</span> range(<span class="number">1</span>,<span class="number">11</span>)}</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">1</span>,<span class="number">1001</span>):</span><br><span class="line">	i2 = i</span><br><span class="line">	<span class="keyword">for</span> j <span class="keyword">in</span> range(<span class="number">1</span>,<span class="number">11</span>):</span><br><span class="line">	dp = i % <span class="number">2</span></span><br><span class="line">	<span class="keyword">if</span> dp == <span class="number">1</span>:</span><br><span class="line">		M[j].append(i2)</span><br><span class="line">	i -= dp</span><br><span class="line">	i /= <span class="number">2</span></span><br><span class="line"></span><br><span class="line">find_bottle = <span class="number">0</span></span><br><span class="line">p_b = poison_bottle</span><br><span class="line">dead_mouse = []</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">1</span>,<span class="number">11</span>)</span><br><span class="line">	dp = p_b % <span class="number">2</span></span><br><span class="line">	<span class="keyword">if</span>  dp == <span class="number">1</span>:</span><br><span class="line">		dead_mouse.insert(<span class="number">0</span>,i)</span><br><span class="line">	p_b -= dp</span><br><span class="line">	p_b /= <span class="number">2</span></span><br><span class="line"><span class="keyword">for</span> n <span class="keyword">in</span> dead_mouse:</span><br><span class="line">	find_bottle += <span class="number">2</span> ** (n<span class="number">-1</span>)</span><br><span class="line"></span><br><span class="line">print(poison_bottle)</span><br><span class="line">print(find_bottle)</span><br><span class="line">print(dead_mouse)</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span></span><br></pre></td></tr></tbody></table></figure></body></html>
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/python/" rel="tag"># python</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/09/20/纳新有感/" rel="next" title="纳新有感">
                <i class="fa fa-chevron-left"></i> 纳新有感
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/10/13/MySQL1/" rel="prev" title="MySQL1">
                MySQL1 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/touxiang.jpg" alt="GodPang">
            
              <p class="site-author-name" itemprop="name">GodPang</p>
              <p class="site-description motion-element" itemprop="description">一只一直在努力的胖子</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">23</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">11</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/GodPang" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/c8a45218e240" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-book"></i>简书</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://lengjibo.github.io/" title="冷逸" target="_blank">冷逸</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://test482.github.io" title="Eliot's Blog" target="_blank">Eliot's Blog</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://prontosil.club/" title="百浪多息" target="_blank">百浪多息</a>
                  </li>
                
              </ul>
            </div>
          

          <div id="music163player">
    <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="330" height="86" src="//music.163.com/outchain/player?type=2&id=38592976&auto=1&height=66"></iframe>
</div>

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Python"><span class="nav-number">1.</span> <span class="nav-text">Python</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#内置对象"><span class="nav-number">1.1.</span> <span class="nav-text">内置对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#表达式"><span class="nav-number">1.2.</span> <span class="nav-text">表达式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#运算符"><span class="nav-number">1.3.</span> <span class="nav-text">运算符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#基本输出函数"><span class="nav-number">1.4.</span> <span class="nav-text">基本输出函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#变量"><span class="nav-number">1.5.</span> <span class="nav-text">变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#赋值语句-statement"><span class="nav-number">1.6.</span> <span class="nav-text">赋值语句    statement</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#函数"><span class="nav-number">1.7.</span> <span class="nav-text">函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#语句-statements"><span class="nav-number">1.8.</span> <span class="nav-text">语句 statements</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#基本输入输出函数："><span class="nav-number">1.9.</span> <span class="nav-text">基本输入输出函数：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#if-语句"><span class="nav-number">1.10.</span> <span class="nav-text">if 语句</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#DAY2"><span class="nav-number">2.</span> <span class="nav-text">DAY2</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#if语句的嵌套"><span class="nav-number">2.1.</span> <span class="nav-text">if语句的嵌套</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#条件表达式"><span class="nav-number">2.2.</span> <span class="nav-text">条件表达式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#pass语句"><span class="nav-number">2.3.</span> <span class="nav-text">pass语句</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#正负号运算符"><span class="nav-number">2.4.</span> <span class="nav-text">正负号运算符</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#循环语句"><span class="nav-number">3.</span> <span class="nav-text">循环语句</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#for循环"><span class="nav-number">3.1.</span> <span class="nav-text">for循环:</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#range-函数"><span class="nav-number">3.2.</span> <span class="nav-text">range()函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#循环嵌套"><span class="nav-number">3.3.</span> <span class="nav-text">循环嵌套</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#while循环："><span class="nav-number">3.4.</span> <span class="nav-text">while循环：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#用循环生成列表"><span class="nav-number">3.5.</span> <span class="nav-text">用循环生成列表</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#DAY3"><span class="nav-number">4.</span> <span class="nav-text">DAY3</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#斐波那契数列："><span class="nav-number">4.1.</span> <span class="nav-text">斐波那契数列：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#函数-1"><span class="nav-number">4.2.</span> <span class="nav-text">函数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#函数的语法："><span class="nav-number">4.2.1.</span> <span class="nav-text">函数的语法：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#函数的作用："><span class="nav-number">4.2.2.</span> <span class="nav-text">函数的作用：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#函数的调用"><span class="nav-number">4.2.3.</span> <span class="nav-text">函数的调用</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#return-语句"><span class="nav-number">4.2.3.1.</span> <span class="nav-text">return 语句</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#位置参数"><span class="nav-number">4.2.3.2.</span> <span class="nav-text">位置参数</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#面向对象编程（oop）"><span class="nav-number">5.</span> <span class="nav-text">面向对象编程（oop）</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#类的创建语法："><span class="nav-number">5.1.</span> <span class="nav-text">类的创建语法：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#类的作用："><span class="nav-number">5.2.</span> <span class="nav-text">类的作用：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#实例创建表达式："><span class="nav-number">5.3.</span> <span class="nav-text">实例创建表达式：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#实例变量的调用语法："><span class="nav-number">5.4.</span> <span class="nav-text">实例变量的调用语法：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#点在模块中的用法："><span class="nav-number">5.5.</span> <span class="nav-text">点在模块中的用法：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#实例变量的赋值规则："><span class="nav-number">5.6.</span> <span class="nav-text">实例变量的赋值规则：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#实例的方法："><span class="nav-number">5.7.</span> <span class="nav-text">实例的方法：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#实例方法的调用语法："><span class="nav-number">5.8.</span> <span class="nav-text">实例方法的调用语法：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#构造方法"><span class="nav-number">5.9.</span> <span class="nav-text">构造方法:</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#作用："><span class="nav-number">5.9.1.</span> <span class="nav-text">作用：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#语法："><span class="nav-number">5.9.2.</span> <span class="nav-text">语法：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#比如：我们已经编写了一个名为Animal的class、有一个run（）的方法可以直接打印："><span class="nav-number">5.9.3.</span> <span class="nav-text">比如：我们已经编写了一个名为Animal的class、有一个run（）的方法可以直接打印：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#当我们需要编写Dog类和Cat类时，就可以之接从Animsl类继承"><span class="nav-number">5.9.4.</span> <span class="nav-text">当我们需要编写Dog类和Cat类时，就可以之接从Animsl类继承</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#继承有什么好处？"><span class="nav-number">5.9.5.</span> <span class="nav-text">继承有什么好处？</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#封装"><span class="nav-number">6.</span> <span class="nav-text">封装</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#模块"><span class="nav-number">7.</span> <span class="nav-text">模块</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#什么是模块："><span class="nav-number">7.0.1.</span> <span class="nav-text">什么是模块：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#模块的作用："><span class="nav-number">7.0.2.</span> <span class="nav-text">模块的作用：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#模块的分类："><span class="nav-number">7.0.3.</span> <span class="nav-text">模块的分类：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#为什么使用模块"><span class="nav-number">7.0.4.</span> <span class="nav-text">为什么使用模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#如何组织一个程序："><span class="nav-number">7.0.5.</span> <span class="nav-text">如何组织一个程序：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#模块的导入"><span class="nav-number">7.0.6.</span> <span class="nav-text">模块的导入:</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#数学模块-math"><span class="nav-number">7.0.6.1.</span> <span class="nav-text">数学模块    math:</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#变量："><span class="nav-number">7.0.6.1.1.</span> <span class="nav-text">变量：</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#时间模块-time"><span class="nav-number">7.0.6.2.</span> <span class="nav-text">时间模块 time</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#模块路径的搜索顺序："><span class="nav-number">7.0.6.3.</span> <span class="nav-text">模块路径的搜索顺序：</span></a></li></ol></li></ol></li></ol><li class="nav-item nav-level-1"><a class="nav-link" href="#DAY5"><span class="nav-number">8.</span> <span class="nav-text">DAY5</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#飞机大战游戏"><span class="nav-number">8.1.</span> <span class="nav-text">飞机大战游戏</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#设计思路："><span class="nav-number">8.2.</span> <span class="nav-text">设计思路：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#游戏组成："><span class="nav-number">8.3.</span> <span class="nav-text">游戏组成：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#业务需求："><span class="nav-number">8.4.</span> <span class="nav-text">业务需求：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#设计模型："><span class="nav-number">8.5.</span> <span class="nav-text">设计模型：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#让tkinter-GUI-程序启动和运行起来需要五个步骤"><span class="nav-number">8.6.</span> <span class="nav-text">让tkinter GUI 程序启动和运行起来需要五个步骤</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#DAY3-1"><span class="nav-number">9.</span> <span class="nav-text">DAY3</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#python里如何拷贝一个对象？（赋值，浅拷贝，深拷贝的区别）"><span class="nav-number">9.1.</span> <span class="nav-text">python里如何拷贝一个对象？（赋值，浅拷贝，深拷贝的区别）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#浅拷贝（copy）：拷贝父对象，不会拷贝对象内部的子对象"><span class="nav-number">9.2.</span> <span class="nav-text">浅拷贝（copy）：拷贝父对象，不会拷贝对象内部的子对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#深拷贝（deecopy）-copy模块的deepcopy方法，完全拷贝了父对象及其子对象"><span class="nav-number">9.3.</span> <span class="nav-text">深拷贝（deecopy）:copy模块的deepcopy方法，完全拷贝了父对象及其子对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二分查找"><span class="nav-number">9.4.</span> <span class="nav-text">二分查找</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#必须是有序的数列"><span class="nav-number">9.4.1.</span> <span class="nav-text">必须是有序的数列</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#快速排序：-递归"><span class="nav-number">9.5.</span> <span class="nav-text">快速排序：         #递归</span></a></li></ol></li></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>
    


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">GodPang</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>



  <div class="footer-custom">Hosted by <a target="_blank" rel="external nofollow" href="https://pages.github.com/">GitHub Pages</a></div>


        
<div class="busuanzi-count">
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: 'RAQiIXnddbLLbBRiBcDuJo3j-gzGzoHsz',
        appKey: 'rhBtL6nW6zYrDqLcVsPX4M51',
        placeholder: '大佬勿喷，文明交流',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  

  

  
  

  

  

  

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>

</body>
</html>
